********************************************************************************
** 	TITLE:		us1992_anes_contact_networks                                  ** 	
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       NES1992                                                       **
**  DATE:	    October 2022 						                          **	
**	VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "us1992_anes_contact_networks", replace

* Open the dataset

use "NES1992.dta", clear

* Generate variable for interview year

gen inty = 1992


**************************
** STATE-LEVEL OUTCOMES **
**************************

* Note: 1 = Republican, 2 = Democrat

gen statewinner = .

replace statewinner = 1 if V900010 == 1
replace statewinner = 1 if V900010 == 2
replace statewinner = 1 if V900010 == 4
replace statewinner = 2 if V900010 == 5
replace statewinner = 2 if V900010 == 6
replace statewinner = 2 if V900010 == 8
replace statewinner = 2 if V900010 == 9
replace statewinner = 2 if V900010 == 10
replace statewinner = 2 if V900010 == 11
replace statewinner = 1 if V900010 == 12
replace statewinner = 2 if V900010 == 13
replace statewinner = 2 if V900010 == 15
replace statewinner = 1 if V900010 == 16
replace statewinner = 2 if V900010 == 17
replace statewinner = 1 if V900010 == 18
replace statewinner = 2 if V900010 == 19
replace statewinner = 1 if V900010 == 20
replace statewinner = 2 if V900010 == 21
replace statewinner = 2 if V900010 == 22
replace statewinner = 2 if V900010 == 23
replace statewinner = 2 if V900010 == 24
replace statewinner = 2 if V900010 == 25
replace statewinner = 2 if V900010 == 26
replace statewinner = 2 if V900010 == 27
replace statewinner = 1 if V900010 == 28
replace statewinner = 2 if V900010 == 29
replace statewinner = 2 if V900010 == 30
replace statewinner = 1 if V900010 == 31
replace statewinner = 2 if V900010 == 32
replace statewinner = 2 if V900010 == 33
replace statewinner = 2 if V900010 == 34
replace statewinner = 2 if V900010 == 35
replace statewinner = 2 if V900010 == 36
replace statewinner = 1 if V900010 == 37
replace statewinner = 1 if V900010 == 38
replace statewinner = 2 if V900010 == 39
replace statewinner = 1 if V900010 == 40
replace statewinner = 2 if V900010 == 41
replace statewinner = 2 if V900010 == 42
replace statewinner = 2 if V900010 == 44
replace statewinner = 1 if V900010 == 45
replace statewinner = 1 if V900010 == 46
replace statewinner = 2 if V900010 == 47
replace statewinner = 1 if V900010 == 48
replace statewinner = 1 if V900010 == 49
replace statewinner = 2 if V900010 == 50
replace statewinner = 1 if V900010 == 51
replace statewinner = 2 if V900010 == 53
replace statewinner = 2 if V900010 == 54
replace statewinner = 2 if V900010 == 55
replace statewinner = 1 if V900010 == 56


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by state (absolute difference between Democratic and Republican candidates)

gen margin = .

replace margin = 6.765343 if V900010 == 1
replace margin = 9.170385 if V900010 == 2
replace margin = 1.952686 if V900010 == 4
replace margin = 17.72456 if V900010 == 5
replace margin = 13.39192 if V900010 == 6
replace margin = 4.258976 if V900010 == 8
replace margin = 6.435333 if V900010 == 9
replace margin = 8.197296 if V900010 == 10
replace margin = 75.54576 if V900010 == 11
replace margin = 1.912376 if V900010 == 12
replace margin = .5908318 if V900010 == 13
replace margin = 11.39571 if V900010 == 15
replace margin = 13.61338 if V900010 == 16
replace margin = 14.24221 if V900010 == 17
replace margin = 6.112873 if V900010 == 18
replace margin = 6.013699 if V900010 == 19
replace margin = 5.143028 if V900010 == 20
replace margin = 3.210262 if V900010 == 21
replace margin = 4.61364 if V900010 == 22
replace margin = 8.376169 if V900010 == 23
replace margin = 14.1832 if V900010 == 24
replace margin = 18.51702 if V900010 == 25
replace margin = 7.398041 if V900010 == 26
replace margin = 11.63382 if V900010 == 27
replace margin = 8.915833 if V900010 == 28
replace margin = 10.15001 if V900010 == 29
replace margin = 2.508629 if V900010 == 30
replace margin = 17.19405 if V900010 == 31
replace margin = 2.63076 if V900010 == 32
replace margin = 1.220371 if V900010 == 33
replace margin = 2.372929 if V900010 == 34
replace margin = 8.560383 if V900010 == 35
replace margin = 18.43656 if V900010 == 36
replace margin = .7894402 if V900010 == 37
replace margin = 12.03247 if V900010 == 38
replace margin = 1.834671 if V900010 == 39
replace margin = 8.62101 if V900010 == 40
replace margin = 9.951641 if V900010 == 41
replace margin = 9.018955 if V900010 == 42
replace margin = 18.02036 if V900010 == 44
replace margin = 4.230816 if V900010 == 45
replace margin = 3.518173 if V900010 == 46
replace margin = 4.651428 if V900010 == 47
replace margin = 3.481564 if V900010 == 48
replace margin = 18.71013 if V900010 == 49
replace margin = 15.69549 if V900010 == 50
replace margin = 4.371292 if V900010 == 51
replace margin = 11.44462 if V900010 == 53
replace margin = 13.02179 if V900010 == 54
replace margin = 4.354336 if V900010 == 55
replace margin = 5.596748 if V900010 == 56


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen surveydate = mdy(V923026,V923027,inty)

format %tdMon_DD,_CCYY surveydate

gen edate = 19921103

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = (electiondate - surveydate) - 1 // Substract 1 to correct for election date

* Gender

gen male = V900547

recode male (0=.)

recode male (2=0)

* Age

gen age = V923903

replace age = . if age < 18

* Education

gen education = V900557

recode education (0=.)
recode education (98=.)
recode education (99=.)

* Interest for election

gen interest = V923101

recode interest (9=.)

replace interest = 6 - interest

replace interest = 2 if interest == 3
replace interest = 3 if interest == 5

* Caring about outcome (national)

gen care_whole = V923106

recode care_whole (8=.)
recode care_whole (9=.)

recode care_whole (3=0)

* Closeness of election (national)

gen closeness_whole = V923103

recode closeness_whole (0=.)
recode closeness_whole (8=.)
recode closeness_whole (9=.)

recode closeness_whole (1=0)
recode closeness_whole (3=1)

* Closeness of election (state)

gen closeness_state = V923105

recode closeness_state (0=.)
recode closeness_state (8=.)
recode closeness_state (9=.)

recode closeness_state (1=0)
recode closeness_state (3=1)

* Party identification scale (national)

gen pidscale = V900320

recode pidscale (7=.) // Other minor party (only one respondent) recoded as missing data
recode pidscale (8=3) // Apolitical recoded as Independent
recode pidscale (9=.) // NA recoded as missing data

replace pidscale = pidscale + 1

gen pidscale_whole = 8 - pidscale

label define pidscale 1 "Strong loser PID" 2 "Weak loser PID" 3 "Leaner loser PID" 4 "No PID" 5 "Leaner winner PID" 6 "Weak winner PID" 7 "Strong winner PID"
label values pidscale_whole pidscale

* Party identification scale (state)

gen pidscale_state = pidscale if statewinner == 1
replace pidscale_state = 8 - pidscale if statewinner == 2

label values pidscale_state pidscale

* TV news attentiveness

gen watchtv = V923201

gen tv = V923202

recode tv (0=.)
recode tv (8=.)
recode tv (9=.)

replace tv = 6 - tv

replace tv = 1 if watchtv == 0
replace tv = 1 if watchtv == 8

recode tv (.=-99)

* Press news attentiveness

gen readpress = V923203

gen press = V923205

recode press (0=.)
recode press (8=.)
recode press (9=.)

replace press = 6 - press

replace press = 1 if readpress == 0
replace press = 1 if readpress == 8
replace press = 1 if V923204 == 5

recode press (.=-99)

* Magazine news attentiveness

gen readmagazines = V923206

gen magazines = V923207

recode magazines (0=.)
recode magazines (8=.)
recode magazines (9=.)

replace magazines = 6 - magazines

replace magazines = 1 if readmagazines == 5
replace magazines = 1 if readmagazines == 8

recode magazines (.=-99)

* Radio news attentiveness

gen listenradio = V923208

gen radio = V923209

recode radio (0=.)
recode radio (8=.)
recode radio (9=.)

replace radio = 6 - radio // Note: 3-point scale (rather than 5-point scale)

recode radio (1=2)
recode radio (3=4)

replace radio = 1 if listenradio == 5
replace radio = 1 if listenradio == 8

recode radio (.=-99)

* News attentiveness index

egen news = rowmax(tv press magazines radio)

recode news (-99=.)

* Dan Quayle - Correct answer (U.S. vice-president) = 1, Incorrect answer = 0

gen quayle = V900395

recode quayle (0=.)
recode quayle (9=.)

recode quayle (5=0)
recode quayle (8=0)

* George Mitchell - Correct answer (Majority Senate leader) = 1, Incorrect answer = 0

gen mitchell = V900396

recode mitchell (0=.)
recode mitchell (9=.)

recode mitchell (5=0)
recode mitchell (8=0)

* William Rehnquist - Correct answer (Supreme Court Chief Justice) = 1, Incorrect answer = 0

gen rehnquist = V900397

recode rehnquist (0=.)
recode rehnquist (9=.)

recode rehnquist (5=0)
recode rehnquist (8=0)

* Mikhail Gorbachev - Correct answer (USSR President) = 1, Incorrect answer = 0

gen gorbachev = V900398

recode gorbachev (0=.)
recode gorbachev (9=.)

recode gorbachev (5=0)
recode gorbachev (8=0)

* Margaret Thatcher - Correct answer (British Prime Minister) = 1, Incorrect answer = 0

gen thatcher = V900399

recode thatcher (0=.)
recode thatcher (9=.)

recode thatcher (5=0)
recode thatcher (8=0)

* Nelson Mandela - Correct answer (ANC leader) = 1, Incorrect answer = 0

gen mandela = V900400

recode mandela (0=.)
recode mandela (9=.)

recode mandela (5=0)
recode mandela (8=0)

* Tom Foley - Correct answer (House speaker) = 1, Incorrect answer = 0

gen foley = V900401

recode foley (0=.)
recode foley (9=.)

recode foley (5=0)
recode foley (8=0)

* Party with the most members in the U.S. House before election - Correct answer (Democrat) = 1, Incorrect answer = 0

gen house = V900402

recode house (0=.)
recode house (9=.)

recode house (1=0)
recode house (5=1)
recode house (8=0)

* Party with the most members in the U.S. Senate before election - Correct answer (Democrat) = 1, Incorrect answer = 0

gen senate = V900403

recode senate (0=.)
recode senate (9=.)

recode senate (1=0)
recode senate (5=1)
recode senate (8=0)

* Political knowledge index

gen knowledge = quayle + mitchell + rehnquist + gorbachev + thatcher + mandela + foley + house + senate

* Political discussion

gen discussion = V900070

recode discussion (8=.)
recode discussion (9=.)

replace discussion = 0 if V900068 == 5 | V900069 == 5

gen discussion_3pts = 0 if discussion < 2 & discussion!=.
replace discussion_3pts = 1 if discussion >= 2 & discussion < 4 & discussion!=.
replace discussion_3pts = 2 if discussion >= 4 & discussion!=.

* Political discussion (typical week)

gen discussion_typical = V900069

recode discussion_typical (0=.)
recode discussion_typical (8=.)
recode discussion_typical (9=.)

replace discussion_typical = 5 - discussion_typical

replace discussion_typical = 0 if V900068 == 5


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Forecasts (1 = Republican, 2 = Democrat, 3 = Perot, 7 = other)

gen forecast_whole = V923102

recode forecast_whole (9=.)

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=2 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 2


******************************
** STATE-LEVEL EXPECTATIONS **
******************************

* Forecasts (1 = Republican, 2 = Democrat, 3 = Perot, 7 = other)

gen forecast_state = V923104

recode forecast_state (9=.)

replace forecast_state = . if V900010 == 0

* Identify correct forecasts

gen correct_state_d = 0 if forecast_state!=statewinner & forecast_state!=.
replace correct_state_d = 1 if forecast_state == statewinner & forecast_state!=.


**********
** SAVE **
**********

save "us1992_anes.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion pidscale_whole interest news knowledge i.care_whole i.closeness_whole age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (state)

melogit correct_state_d discussion pidscale_state interest news knowledge i.closeness_state age i.male education time margin || V900010: , or
estimates table, star(.05 .01 .001)

tab correct_state_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_state_d "State winner (DV)"
label variable discussion "Discussion"
label variable pidscale_whole "National PID"
label variable pidscale_state "State PID"
label variable interest "Interest"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable care_whole "Caring about outcome"
label variable closeness_whole "Perceived closeness"
label variable closeness_state "Perceived closeness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"
label variable margin "Margin"

quietly logistic correct_whole_d discussion pidscale_whole interest news knowledge i.care_whole i.closeness_whole age i.male education time

estpost tabstat correct_whole_d discussion pidscale_whole interest news knowledge care_whole closeness_whole age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us1992_anes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1992 American presidential election (ANES), national level") replace

eststo clear

quietly melogit correct_state_d discussion pidscale_state interest news knowledge i.closeness_state age i.male education time margin || V900010: , or

estpost tabstat correct_state_d discussion pidscale_state interest news knowledge closeness_state age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us1992_anes_summary_state.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1992 American presidential election (ANES), state level") replace

eststo clear

log close